package androids.dao;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import androids.excepcion.DAOExcepcion;
import androids.modelo.TipoEntrega;
import androids.util.ConexionBD;

public class TipoEntregaDAO extends BaseDAO {

	public void insertar(TipoEntrega vo) throws DAOExcepcion {
		System.out.println("TipoEntregaDAO: insertar(TipoEntrega vo)");
		String query = "INSERT INTO tipo_entrega(id_tipo_entrega, nombre, descripcion) VALUES (?,?,?)";
		Connection con = null;
		PreparedStatement stmt = null;
		try {
			con = ConexionBD.obtenerConexion();
			stmt = con.prepareStatement(query);
			stmt.setInt(1, vo.getIdTipoEntrega());
			stmt.setString(2, vo.getNombre());
			stmt.setString(3, vo.getDescripcion());
			int i = stmt.executeUpdate();
			if (i != 1) {
				throw new SQLException("No se pudo insertar la categoria");
			}
		} catch (SQLException e) {
			System.err.println(e.getMessage());
			throw new DAOExcepcion(e.getMessage());
		} finally {
			this.cerrarStatement(stmt);
			this.cerrarConexion(con);
		}
	}
}
//
///**
// * Servlet implementation class TipoEntregaDAO
// */
//@WebServlet("/TipoEntregaDAO")
//public class TipoEntregaDAO extends HttpServlet {
//	private static final long serialVersionUID = 1L;
//       
//    /**
//     * @see HttpServlet#HttpServlet()
//     */
//    public TipoEntregaDAO() {
//        super();
//        // TODO Auto-generated constructor stub
//    }
//
//	/**
//	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
//	 */
//	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		// TODO Auto-generated method stub
//	}
//
//	/**
//	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
//	 */
//	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//		// TODO Auto-generated method stub
//	}
//
//}
